public class L641 {

    public static void main(String[] args) {
        MyCircularDeque myCircularDeque = new MyCircularDeque(3);
        myCircularDeque.insertLast(1);
        myCircularDeque.insertLast(2);
        myCircularDeque.insertFront(3);
        myCircularDeque.insertFront(4);
        myCircularDeque.getRear();
        myCircularDeque.isFull();
        myCircularDeque.deleteLast();
        myCircularDeque.insertFront(4);
        myCircularDeque.getFront();
    }

}
class MyCircularDeque {
    int front ;
    int tail;
    int[] container;
    int n;
    public MyCircularDeque(int k) {
        container = new int[k+1];
        front = tail = 0;
        n = k+1;
    }

    public boolean insertFront(int value) {
        if (isFull()) return false;
        int index = (front+n-1)%n;
        front = index;
        container[front] = value;
        return true;
    }

    public boolean insertLast(int value) {
        if (isFull()) return false;
        container[tail] = value;
        tail = (tail+1)%n;
        return true;
    }

    public boolean deleteFront() {
        if (isEmpty()) return false;
        front = (front+1)%n;
        return true;
    }

    public boolean deleteLast() {
        if (isEmpty()) return false;
        tail = (tail+n-1)%n;
        return true;
    }

    public int getFront() {
        return isEmpty()?-1:container[front];
    }

    public int getRear() {
        return isEmpty()?-1:container[(tail+n-1)%n];
    }

    public boolean isEmpty() {
        return front == tail;
    }

    public boolean isFull() {
        return front == (tail+1)%n;
    }
}